// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   DateUtil.java

package com.ronglian.register_mini_program.util;

import org.apache.commons.lang3.StringUtils;

import java.io.PrintStream;
import java.sql.Timestamp;
import java.text.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class DateUtil {

    public DateUtil() {
    }

    public static DateTimeFormatter getDateTimeFormatter() {
        return dateFormatter;
    }

    public static Date Str2Date(String strDate) {
        if (StringUtils.isBlank(strDate))
            return null;
        try {
            return formatter2.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date getNowDate() {
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateString = formatter.format(new Date());
            return formatter.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date getNowDateShort() {
        String dateString = formatter.format(new Date());
        ParsePosition pos = new ParsePosition(8);
        Date currentTime_2 = formatter.parse(dateString, pos);
        return currentTime_2;
    }

    public static String getStringDate() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(new Date());
        return dateString;
    }

    public static String getStringAllDate() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String dateString = formatter.format(new Date());
        return dateString;
    }

    public static String getStringDateShort() {
        String dateString = formatter.format(new Date());
        return dateString;
    }

    public static String getTimeShort() {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        String dateString = formatter.format(new Date());
        return dateString;
    }

    public static Date strToDateMiddle(String strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }

    public static Date strToDateLong(String strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }


    public static String dateToStrLong(Date dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(dateDate);
        return dateString;
    }

    public static String dateToStr(Date dateDate) {
        String dateString = formatter.format(dateDate);
        return dateString;
    }

    public static String dateToStr2(Date dateDate) {
        String dateString = formatter2.format(dateDate);
        return dateString;
    }

    public static String dateToStr(LocalDate dateDate) {
        String dateString = dateFormatter.format(dateDate);
        return dateString;
    }

    public static Date strToDate(String strDate) {
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }

    public static Timestamp strToDateSql(String strDate) {
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter2.parse(strDate, pos);
        return new Timestamp(strtodate.getTime());
    }

    public static Date getNow() {
        Date currentTime = new Date();
        return currentTime;
    }

    public static Date getLastDate(long day) {
        Date date = new Date();
        long date_3_hm = date.getTime() - 0x74bad00L * day;
        Date date_3_hm_date = new Date(date_3_hm);
        return date_3_hm_date;
    }

    public static String getStringToday() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String getTodayShort() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String getHHMMSS(String value) {
        String hour = "00";
        String minute = "00";
        String second = "00";
        if (value != null && !value.trim().equals("")) {
            int v_int = Integer.valueOf(value).intValue();
            hour = (new StringBuilder()).append(v_int / 3600).append("").toString();
            minute = (new StringBuilder()).append((v_int % 3600) / 60).append("").toString();
            second = (new StringBuilder()).append(v_int % 3600 % 60).append("").toString();
        }
        return (new StringBuilder()).append(hour.length() <= 1 ? (new StringBuilder()).append("0").append(hour).toString() : hour).append(":").append(minute.length() <= 1 ? (new StringBuilder()).append("0").append(minute).toString() : minute).append(":").append(second.length() <= 1 ? (new StringBuilder()).append("0").append(second).toString() : second).toString();
    }

    public static String getHour() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        String hour = dateString.substring(11, 13);
        return hour;
    }

    public static String getTime() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        String min = dateString.substring(14, 16);
        return min;
    }

    public static String getUserDate(String sformat) {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(sformat);
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String getTwoHour(String st1, String st2) {
        String kk[] = null;
        String jj[] = null;
        kk = st1.split(":");
        jj = st2.split(":");
        if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0]))
            return "0";
        double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1]) / 60D;
        double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1]) / 60D;
        if (y - u > 0.0D)
            return (new StringBuilder()).append(y - u).append("").toString();
        else
            return "0";
    }

    public static String getTwoDay(String sj1, String sj2) {
        long day = 0L;
        try {
            Date date = formatter.parse(sj1);
            Date mydate = formatter.parse(sj2);
            day = (date.getTime() - mydate.getTime()) / 0x5265c00L;
        } catch (Exception e) {
            return "";
        }
        return (new StringBuilder()).append(day).append("").toString();
    }

    public static String getPreTime(String sj1, String jj) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String mydate1 = "";
        try {
            Date date1 = format.parse(sj1);
            long Time = date1.getTime() / 1000L + (long) (Integer.parseInt(jj) * 60);
            date1.setTime(Time * 1000L);
            mydate1 = format.format(date1);
        } catch (Exception exception) {
        }
        return mydate1;
    }

    public static String getNextDay(String nowdate, String delay) {
        try {
            String mdate = "";
            Date d = strToDate(nowdate);
            long myTime = d.getTime() / 1000L + (long) (Integer.parseInt(delay) * 24 * 60 * 60);
            d.setTime(myTime * 1000L);
            mdate = formatter.format(d);
            return mdate;
        } catch (Exception e) {
            return "";
        }
    }

    public static String getFromNow(int day) {
        Date date = new Date();
        long dateTime = date.getTime() / 1000L + (long) (day * 24 * 60 * 60);
        date.setTime(dateTime * 1000L);
        return formatter2.format(date);
    }

    public static boolean isLeapYear(String ddate) {
        Date d = strToDate(ddate);
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.setTime(d);
        int year = gc.get(1);
        if (year % 400 == 0)
            return true;
        if (year % 4 == 0)
            return year % 100 != 0;
        else
            return false;
    }

    public static String getEDate(String str) {
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(str, pos);
        String j = strtodate.toString();
        String k[] = j.split(" ");
        return (new StringBuilder()).append(k[2]).append(k[1].toUpperCase()).append(k[5].substring(2, 4)).toString();
    }

    public static String getEndDateOfMonth(String dat) {
        String str = dat.substring(0, 8);
        String month = dat.substring(5, 7);
        int mon = Integer.parseInt(month);
        if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12)
            str = (new StringBuilder()).append(str).append("31").toString();
        else if (mon == 4 || mon == 6 || mon == 9 || mon == 11)
            str = (new StringBuilder()).append(str).append("30").toString();
        else if (isLeapYear(dat))
            str = (new StringBuilder()).append(str).append("29").toString();
        else
            str = (new StringBuilder()).append(str).append("28").toString();
        return str;
    }

    public static boolean isSameWeekDates(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal1.setTime(date1);
        cal2.setTime(date2);
        int subYear = cal1.get(1) - cal2.get(1);
        if (0 == subYear) {
            if (cal1.get(3) == cal2.get(3))
                return true;
        } else if (1 == subYear && 11 == cal2.get(2)) {
            if (cal1.get(3) == cal2.get(3))
                return true;
        } else if (-1 == subYear && 11 == cal1.get(2) && cal1.get(3) == cal2.get(3))
            return true;
        return false;
    }

    public static String getSeqWeek() {
        Calendar c = Calendar.getInstance(Locale.CHINA);
        String week = Integer.toString(c.get(3));
        if (week.length() == 1)
            week = (new StringBuilder()).append("0").append(week).toString();
        String year = Integer.toString(c.get(1));
        return (new StringBuilder()).append(year).append(week).toString();
    }

    public static String getWeek(String sdate, String num) {
        Date dd = strToDate(sdate);
        Calendar c = Calendar.getInstance();
        c.setTime(dd);
        if (num.equals("1"))
            c.set(7, 2);
        else if (num.equals("2"))
            c.set(7, 3);
        else if (num.equals("3"))
            c.set(7, 4);
        else if (num.equals("4"))
            c.set(7, 5);
        else if (num.equals("5"))
            c.set(7, 6);
        else if (num.equals("6"))
            c.set(7, 7);
        else if (num.equals("0"))
            c.set(7, 1);
        return (new SimpleDateFormat("yyyy-MM-dd")).format(c.getTime());
    }

    public static String getWeek(String sdate) {
        Date date = strToDate(sdate);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return (new SimpleDateFormat("EEEE")).format(c.getTime());
    }

    public static String getWeekStr(String sdate) {
        String str = "";
        str = getWeek(sdate);
        if ("1".equals(str))
            str = "\u661F\u671F\u65E5";
        else if ("2".equals(str))
            str = "\u661F\u671F\u4E00";
        else if ("3".equals(str))
            str = "\u661F\u671F\u4E8C";
        else if ("4".equals(str))
            str = "\u661F\u671F\u4E09";
        else if ("5".equals(str))
            str = "\u661F\u671F\u56DB";
        else if ("6".equals(str))
            str = "\u661F\u671F\u4E94";
        else if ("7".equals(str))
            str = "\u661F\u671F\u516D";
        return str;
    }

    public static long getDays(String date1, String date2) {
        if (date1 == null || date1.equals(""))
            return 0L;
        if (date2 == null || date2.equals(""))
            return 0L;
        Date date = null;
        Date mydate = null;
        try {
            date = formatter.parse(date1);
            mydate = formatter.parse(date2);
        } catch (Exception exception) {
        }
        long day = (date.getTime() - mydate.getTime()) / 0x5265c00L;
        return day;
    }

    public static String getNowMonth(String sdate) {
        sdate = (new StringBuilder()).append(sdate.substring(0, 8)).append("01").toString();
        Date date = strToDate(sdate);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int u = c.get(7);
        String newday = getNextDay(sdate, (new StringBuilder()).append(1 - u).append("").toString());
        return newday;
    }

    public static String getNo(int k) {
        return (new StringBuilder()).append(getUserDate("yyyyMMddhhmmss")).append(getRandom(k)).toString();
    }

    public static String getRandom(int i) {
        Random jjj = new Random();
        if (i == 0)
            return "";
        String jj = "";
        for (int k = 0; k < i; k++)
            jj = (new StringBuilder()).append(jj).append(jjj.nextInt(9)).toString();

        return jj;
    }

    public static boolean RightDate(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        if (date == null)
            return false;
        if (date.length() > 10)
            sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        else
            sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            sdf.parse(date);
        } catch (ParseException pe) {
            return false;
        }
        return true;
    }

    public static String getStringDateMonth(String sdate, String nd, String yf, String rq, String format) {
        Date currentTime = new Date();
        String dateString = formatter.format(currentTime);
        String s_nd = dateString.substring(0, 4);
        String s_yf = dateString.substring(5, 7);
        String s_rq = dateString.substring(8, 10);
        String sreturn = "";
        if (sdate == null || sdate.equals("")) {
            if (nd.equals("1")) {
                sreturn = s_nd;
                if (format.equals("1"))
                    sreturn = (new StringBuilder()).append(sreturn).append("\u5E74").toString();
                else if (format.equals("2"))
                    sreturn = (new StringBuilder()).append(sreturn).append("-").toString();
                else if (format.equals("3"))
                    sreturn = (new StringBuilder()).append(sreturn).append("/").toString();
                else if (format.equals("5"))
                    sreturn = (new StringBuilder()).append(sreturn).append(".").toString();
            }
            if (yf.equals("1")) {
                sreturn = (new StringBuilder()).append(sreturn).append(s_yf).toString();
                if (format.equals("1"))
                    sreturn = (new StringBuilder()).append(sreturn).append("\u6708").toString();
                else if (format.equals("2"))
                    sreturn = (new StringBuilder()).append(sreturn).append("-").toString();
                else if (format.equals("3"))
                    sreturn = (new StringBuilder()).append(sreturn).append("/").toString();
                else if (format.equals("5"))
                    sreturn = (new StringBuilder()).append(sreturn).append(".").toString();
            }
            if (rq.equals("1")) {
                sreturn = (new StringBuilder()).append(sreturn).append(s_rq).toString();
                if (format.equals("1"))
                    sreturn = (new StringBuilder()).append(sreturn).append("\u65E5").toString();
            }
        } else {
            sdate = getOKDate(sdate);
            s_nd = sdate.substring(0, 4);
            s_yf = sdate.substring(5, 7);
            s_rq = sdate.substring(8, 10);
            if (nd.equals("1")) {
                sreturn = s_nd;
                if (format.equals("1"))
                    sreturn = (new StringBuilder()).append(sreturn).append("\u5E74").toString();
                else if (format.equals("2"))
                    sreturn = (new StringBuilder()).append(sreturn).append("-").toString();
                else if (format.equals("3"))
                    sreturn = (new StringBuilder()).append(sreturn).append("/").toString();
                else if (format.equals("5"))
                    sreturn = (new StringBuilder()).append(sreturn).append(".").toString();
            }
            if (yf.equals("1")) {
                sreturn = (new StringBuilder()).append(sreturn).append(s_yf).toString();
                if (format.equals("1"))
                    sreturn = (new StringBuilder()).append(sreturn).append("\u6708").toString();
                else if (format.equals("2"))
                    sreturn = (new StringBuilder()).append(sreturn).append("-").toString();
                else if (format.equals("3"))
                    sreturn = (new StringBuilder()).append(sreturn).append("/").toString();
                else if (format.equals("5"))
                    sreturn = (new StringBuilder()).append(sreturn).append(".").toString();
            }
            if (rq.equals("1")) {
                sreturn = (new StringBuilder()).append(sreturn).append(s_rq).toString();
                if (format.equals("1"))
                    sreturn = (new StringBuilder()).append(sreturn).append("\u65E5").toString();
            }
        }
        return sreturn;
    }

    public static String getNextMonthDay(String sdate, int m) {
        sdate = getOKDate(sdate);
        int year = Integer.parseInt(sdate.substring(0, 4));
        int month = Integer.parseInt(sdate.substring(5, 7));
        month += m;
        if (month < 0) {
            month += 12;
            year--;
        } else if (month > 12) {
            month -= 12;
            year++;
        }
        String smonth = "";
        if (month < 10)
            smonth = (new StringBuilder()).append("0").append(month).toString();
        else
            smonth = (new StringBuilder()).append("").append(month).toString();
        return (new StringBuilder()).append(year).append("-").append(smonth).append("-10").toString();
    }

    public static String getOKDate(String sdate) {
        if (sdate == null || sdate.equals(""))
            return getStringDateShort();
        if (sdate.length() == 8)
            sdate = (new StringBuilder()).append(sdate.substring(0, 4)).append("-").append(sdate.substring(4, 6)).append("-").append(sdate.substring(6, 8)).toString();
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(sdate, pos);
        String dateString = formatter.format(strtodate);
        return dateString;
    }

    private static String getBeforeDay(Calendar cl) {
        cl.add(5, -1);
        return formatter.format(cl.getTime());
    }

    private static String getAfterDay(Calendar cl) {
        cl.add(5, 1);
        return formatter.format(cl.getTime());
    }

    private static String getDateAMPM() {
        GregorianCalendar ca = new GregorianCalendar();
        int i = ca.get(9);
        return i != 0 ? "PM" : "AM";
    }

    private static int compareToDate(String date1, String date2) {
        return date1.compareTo(date2);
    }

    private static int compareToDateString(String date1, String date2) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int i = 0;
        try {
            long ldate1 = formatter.parse(date1).getTime();
            long ldate2 = formatter.parse(date2).getTime();
            if (ldate1 > ldate2)
                i = 1;
            else if (ldate1 == ldate2)
                i = 0;
            else
                i = -1;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return i;
    }

    public static String[] getFiveDate() {
        String dates[] = new String[2];
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String five = " 05:00:00";
        if (getDateAMPM().equals("AM") && compareToDateString(getStringDate(), (new StringBuilder()).append(getStringDateShort()).append(five).toString()) == -1) {
            dates[0] = (new StringBuilder()).append(getBeforeDay(calendar)).append(five).toString();
            dates[1] = (new StringBuilder()).append(getStringDateShort()).append(five).toString();
        } else {
            dates[0] = (new StringBuilder()).append(getStringDateShort()).append(five).toString();
            dates[1] = (new StringBuilder()).append(getAfterDay(calendar)).append(five).toString();
        }
        return dates;
    }

    public static String getFiveDate2() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String five = " 05:00:00";
        String reStr = "";
        if (getDateAMPM().equals("AM") && compareToDateString(getStringDate(), (new StringBuilder()).append(getStringDateShort()).append(five).toString()) == -1)
            reStr = getBeforeDay(calendar);
        else
            reStr = getStringDateShort();
        return reStr;
    }

    public static void main(String args[]) {
        Date date = strToDate("2018-01-18");
        System.out.println(date);
        String nextDay = getNextDay("2018-01-18", "1");
        System.out.println(nextDay);
        String startday = "20150201";
        String preTime = getPreTime(getStringDate(), "20");
        System.out.println((new StringBuilder()).append("\u5E74\u6708\u65E5").append(preTime).toString());
    }

    public static String pattern;
    public static SimpleDateFormat formatter;
    public static SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static DateTimeFormatter dateFormatter;

    static {
        pattern = "yyyy-MM-dd";
        formatter = new SimpleDateFormat(pattern);
        dateFormatter = DateTimeFormatter.ofPattern(pattern);
    }

    //给现在时间加几个小时
    public static Date addSomeHours(double hour) {
        long currentTime = System.currentTimeMillis();
        //2、在这个基础上加上30分钟：
        currentTime += hour * 60 * 1000;
        // 3、格式化时间，获取到的就是当前时间半个小时之后的时间
        Date date = new Date(currentTime);
        return date;
    }

    //给现在时间减少几个小时
    public static Date reduceSomeHours(double hour) {
        long currentTime = System.currentTimeMillis();
        //2、在这个基础上加上30分钟：
        currentTime -= hour * 60 * 1000;
        // 3、格式化时间，获取到的就是当前时间半个小时之后的时间
        Date date = new Date(currentTime);
        return date;
    }


}
